<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>用户注册</title>
    <link rel="stylesheet" href="../themes/mall/default/styles/share/css/hui.css">
    <link rel="stylesheet" href="../themes/mall/default/styles/share/css/style.css">
    <script src="/mobile/themes/mall/default/styles/share/js/com.js"></script>
    <script src="/mobile/themes/mall/default/styles/share/js/hui.js"></script>
    <script src="/mobile/themes/mall/default/styles/share/js/template-web.js"></script>
    <style>
        ::-webkit-input-placeholder { /* WebKit browsers */
            color: #999;
            font-size: 16px;
        }

        ::-moz-placeholder { /* Mozilla Firefox 19+ */
            color: #999;
            font-size: 16px;
        }

        :-ms-input-placeholder { /* Internet Explorer 10+ */
            color: #999;
            font-size: 16px;
        }
    </style>
</head>
<body>
<div style="background: no-repeat center center none;background-size: cover" class="w100per h100per" id="bgcontain">
    <div style="padding: -1px 0 14px 18px">
        <img src="/mobile/themes/mall/default/styles/share/img/bg.jpg"  alt="">
    </div>
    <!--<div class="pad_t10 txt_center">-->
        <!--<h5 style="font-size: 27px;padding-left: -25px;margin-left: -120px;">专业奢侈品</h5>-->
        <!--<h5 style="font-size: 27px;padding-left: -25px;margin-left: -90px;">跨境电商平台</h5>-->
    <!--</div>-->

    <div id="contain"></div>
</div>

<script type="text/html" id="tpl">
    <div class="pad_l10 pad_r10 pad_b16">
        <div class="bdr8 pad_l10 pad_r10 bgcfff bd_allred">
            <div class="bd_b" style="padding: 14px 0;line-height: 28px">
                <div class="table">
                    <div class="fs13 c333 wem6">
                        <div class="pad_l10" style="font-size: 16px;">+86   |  </div>
                    </div>
                    <div><input class="fs13 w100per" type="number" placeholder="请输入手机号" name="phone"></div>
                </div>
            </div>
            <div class="bd_b" style="padding: 14px 0;line-height: 28px">
                <div class="table">
                    <!--<div class="fs13 c333 wem6">-->
                        <!--<div class="pad_l10">密码</div>-->
                    <!--</div>-->
                    <div><input class="fs13 w100per" type="password" placeholder="请输入密码" name="password"></div>
                </div>
            </div>
            <div class="bd_b" style="padding: 14px 0;line-height: 28px">
                <div class="table">
                    <!--<div class="fs13 c333 wem6">-->
                        <!--<div class="pad_l10">确认密码</div>-->
                    <!--</div>-->
                    <div><input class="fs13 w100per" type="password" placeholder="确认密码" name="confirm_password"></div>
                </div>
            </div>
            <div class="bd_b" style="padding: 14px 0;line-height: 28px">
                <div class="table" style="">
                    <!--<div class="fs13 c333 wem6">-->
                        <!--<div class="pad_l10">验证码</div>-->
                    <!--</div>-->
                    <div><input class="fs13 w100per" type="number" placeholder="请输入短信验证码" name="yzm"></div>
                    <div class="wem7 txt_right">
                        <a href="javascript:sendmafun();" class="bgcred bdr4 wem6 txt_center inblock cfff fs13" id="sendma">获取验证码</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="pad10">
        <a href="javascript:submit();" class="cfff fs15 txt_center bgcred bdr4 pad_t10 pad_b10 block">注册并下载</a>
    </div>
</script>
<script src="http://api.map.baidu.com/api?ak=Zv7B7obCxdAyWVl9M0GLBdSiKd8RLbGE&v=2.0&services=false"></script>
<script>

    // window.onload = function () {
//         var u = navigator.userAgent;
//         if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
//             window.location.href = "cloud-modaapp://cloud-moda?goods_id="+{$goods_id};
//         } else if (u.indexOf('iPhone') > -1) {//苹果手机
//             window.location.href = "cloud-modaapp://cloud-moda";
//         } else if (u.indexOf('Windows Phone') > -1) {//winphone手机
// // window.location.href = "mobile/index.html";
//         }

    // }
    var city = '';
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            lat = r.point.lat;
            lng = r.point.lng;
            city = r.address.province;
        }
    })

    var canajax=true;
    //
    if(!Getvariable('token')){
    	// hui.toast('少token参数');
    }else {
        pre_loading_txt(0);
    }

    var data={
        tel:'',
        code:''
    };
    function renderhtml(){
        document.getElementById('contain').innerHTML=template('tpl', data);
    }
    data.tel=Getvariable('phone');
    renderhtml();
    pre_loading_txt(100);
    // }

    //防止 键盘弹出后 背景错位
    // var h=window.innerHeight<500?500:window.innerHeight;
    // console.log(h)
    document.getElementById('bgcontain').style.height='650px';

    //发送验证码
    var sendmaobj=document.getElementById('sendma');

    var sign = '';
    function sendmafun(){
        if(!canajax){
            return false;
        }

        if(sendmaobj.innerHTML=='获取验证码' || sendmaobj.innerHTML=='重新发送'){
            var phone=document.getElementsByName('phone')[0].value;
            var confirm_password=document.getElementsByName('confirm_password')[0].value;
            var password=document.getElementsByName('password')[0].value;
            if(phone==''){
                hui.toast('请输入手机号');
                return false;
            }
            if(!/^1[3|4|5|6|7|8|9]\d{9}$/.test(phone)){
                hui.toast('手机号不正确');
                return false;
            }

            if(password == ''){
                hui.toast('请输入密码');
                return false;
            }
            if(confirm_password == ''){
                hui.toast('请输入确认密码');
                return false;
            }
            if (password == null || password.length < 6) {
                hui.toast('密码长度不足6位');
                return false;
            }

            if(password != confirm_password){
                hui.toast('两次密码不一致');
                return false;
            }

            //发送短信接口
            hui.post(
                'index.php?app=share&act=send_messages',
                {
                    mobile:phone,
                },
                function(res){
                    canajax=true;
                    res = JSON.parse(res);
                    if (res.code == 1) {
                        sign = res.result.msg_sign;
                        daojishi();
                    } else
                        hui.toast(res.message);
                    toLogin();
                },
                function(res){
                    canajax=true;
                    console.log('error');
                    console.log(res);
                }
            );
        }
    }
    var timer=null;
    var timezhi=60;
    var timecurr=timezhi;
    function daojishi(){
        console.log('enter')
        timecurr=timezhi;
        sendmaobj.innerHTML=timecurr+'s';

        timer=setInterval(function(){
            if(timecurr>1){
                timecurr--;
                sendmaobj.innerHTML=timecurr+'s';
            }else{
                clearInterval(timer);
                timer=null;
                sendmaobj.innerHTML='重新发送';
            }
        },1000);
    }

    //注册
    function submit(){
        if(!canajax){
            return false;
        }
        var phone=document.getElementsByName('phone')[0].value;
        var password=document.getElementsByName('password')[0].value;
        var confirm_password=document.getElementsByName('confirm_password')[0].value;
        var yzm=document.getElementsByName('yzm')[0].value;

        if(phone==''){
            hui.toast('请输入手机号');
            return false;
        }
        if(!/^1[3|4|5|7|6|8|9]\d{9}$/.test(phone)){
            hui.toast('手机号不正确');
            return false;
        }

        if(password == ''){
            hui.toast('请输入密码');
            return false;
        }
        if(confirm_password == ''){
            hui.toast('请输入确认密码');
            return false;
        }
        if (password == null || password.length < 6) {
            hui.toast('密码长度不足6位');
            return false;
        }

        if(password != confirm_password){
            hui.toast('两次密码不一致');
            return false;
        }
        if(yzm==''){
            hui.toast('请输入短信验证码');
            return false;
        }

        canajax=false;
        var type = "{$type}";
        var wish_id = "{$wish_id}";
        var url = 'index.php?app=share&act=shareRegister';
        if(type){
            url = 'index.php?app=share&act=shareWishRegister';
        }
        var chuan={
            phone:phone,
            code:yzm,
            password:password,
            confirm_password:confirm_password,
            msg_sign:sign,
            city:city,
            token:Getvariable('token'),
            wish_id:wish_id
        };
        hui.post(
            url,
            chuan,
            function(res){
                canajax=true;
                res = JSON.parse(res);
                if (res.code == 1) {
                    if(res.result == 'wish'){
                        setTimeout(function(){//两秒后跳转
                            alert("恭喜你注册成功");
                            location.href = "index.php?app=qrcode&act=download"
                        },1000);
                    }else{
                        // hui.toast('注册成功啦，请赶紧下载APP吧');
                        setTimeout(function(){//两秒后跳转
                            alert("注册成功啦，请赶紧下载APP吧");
                            location.href = "index.php?app=qrcode&act=download"
                        },1000);
                    }
                } else if (res.code == -1) {
                    hui.toast(res.msg);
                }else if(res.code == -2){
                    setTimeout(function(){//两秒后跳转
                        alert("您已经注册成功了，请赶紧下载APP吧");
                        location.href = "index.php?app=qrcode&act=download"
                    },1000);
                }
            },
            function(res){
                canajax=true;
                console.log('error');
                console.log(res);
            }
        );
    }
</script>
</body>
</html>